
##########
##参数定义
##########

radius  = 11.75.mm
pitchofscrew = 3.mm
halfpitchofscrew = pitchofscrew/2

scale = halfpitchofscrew*1.732/radius+1

##########
##群组结构
##########

group = Sketchup.active_model.entities.add_group     #最外层群组
group1 = group.entities.add_group                    #圆环体群组
                    

##########
##圆环柱群组
##########

#entities = Sketchup.active_model.entities
center_point = Geom::Point3d.new([0,0,0])
# Create a circle perpendicular to the provided vector.
normal = vector = Z_AXIS
edges = group1.entities.add_circle(center_point, vector, 18.5.mm)      #添加一个直径37mm的圆边线
face = group1.entities.add_face(edges)                                 #以边为界添加面
status = face.pushpull(-60.mm, true)                            #推拉-60mm形成向上的圆柱体

edges2 = group1.entities.add_circle(center_point, vector, 11.75.mm)    #在圆柱底部画一个直径23mm的圆边线

face2 = edges2[0].common_face(edges2[1])                        #利用两边共面引用内径圆的面
status = face2.pushpull(60.mm, true)                            #推拉60mm形成圆环柱

group1.entities.erase_entities(face2)                                  #删除内径圆的面

##########
##螺旋线1
##########

group2 = group.entities.add_group  #螺旋线1群组

for i in 0..19
    
    new_edges = group2.entities.add_arc([0,0,pitchofscrew*i], [1,0,0], [0,0,1], radius, 0, 180.degrees)

    curve = new_edges.first.curve
    points = curve.vertices.map(&:position)
    points.each_with_index { |pt, j| pt.z = (j * halfpitchofscrew/(points.length-1))+ pitchofscrew*i}
    curve.move_vertices(points)

    new_edges = group2.entities.add_arc([0,0,pitchofscrew*i+halfpitchofscrew], [1,0,0], [0,0,1], radius, 180.degrees, 360.degrees)

    curve = new_edges.first.curve
    points = curve.vertices.map(&:position)
    points.each_with_index { |pt, j| pt.z = (j * halfpitchofscrew/(points.length-1)) +halfpitchofscrew + pitchofscrew*i }
    curve.move_vertices(points)


end



##########
##螺旋线2
##########

group3 = group.entities.add_group                    #螺旋线2群组

for i in 0..19
    
    new_edges = group3.entities.add_arc([0,0,pitchofscrew*i], [-1,0,0], [0,0,1], radius, 0, 180.degrees)

    curve = new_edges.first.curve
    points = curve.vertices.map(&:position)
    points.each_with_index { |pt, j| pt.z = (j * halfpitchofscrew/(points.length-1))+ pitchofscrew*i}
    curve.move_vertices(points)

    new_edges = group3.entities.add_arc([0,0,pitchofscrew*i+halfpitchofscrew], [-1,0,0], [0,0,1], radius, 180.degrees, 360.degrees)

    curve = new_edges.first.curve
    points = curve.vertices.map(&:position)
    points.each_with_index { |pt, j| pt.z = (j * halfpitchofscrew/(points.length-1)) +halfpitchofscrew + pitchofscrew*i }
    curve.move_vertices(points)


end

 
##########
##炸开与缩放
##########



array = group3.explode

group2.explode

arcLine3 = array.first.edges.first.all_connected

group1.explode


tr = Geom::Transformation.scaling scale, scale, 1
group.entities.transform_entities(tr, arcLine3)

